#include "CocoMenu.h"


CocoMenu::CocoMenu(QString s)
{
	QAction * item =  new QAction(s, this);
	QMenu * menu = new QMenu();
	menuAppend(item , menu , CocoHieriachy::sharedHieriachy()->RootNode());
	item->setMenu(menu);

	this->setMinimumWidth( 150);
	this->addAction(item);
    QString menuStyle = "  QMenuBar{border-color: rgb(255, 255, 255);background-color: rgb(236, 233, 216);} QMenuBar::item{spacing: 3px; /* spacing between menu bar items */padding: 3px 6px;margin:1px 1px;background: transparent; border: 1px solid transparent; /* reserve space for selection border */border-radius: 2px;}QMenuBar::item:selected { /* when selected using mouse or keyboard */background: #a8a8a8;border-color:rgb(0,0,0); border-width:1px;} QMenuBar::item:pressed { background: #888888;}QMenu::item{ border: 1px solid transparent; /* reserve space for selection border */ padding: 5px 25px 5px 20px; border-radius: 2px; } QMenu::item:selected { border-color: darkblue; background: rgba(100, 100, 100, 150); }";
    menu->setStyleSheet(menuStyle);
    this->setStyleSheet(menuStyle);
}




void CocoMenu::menuAppend( QAction * parent , QMenu * menu, QTreeNode<QCocoNode> * treeNode )
{
	QAction * a_childAction = new QAction(treeNode->m_data.name, menu);
	QVariant v;
	v.setValue<int>(treeNode->m_data.id);

	a_childAction->setData(v);
	menu->addAction(a_childAction);
	if (treeNode->hasChildren() )
	{
//         menu->addSeparator();
//         QAction * a_childMenuAction = new QAction(treeNode->m_data.name + " Children ", menu);
//         menu->addAction(a_childMenuAction);
// 		QMenu * childMenu = new QMenu(menu);
//         menu->addSeparator();
		for (int i = 0 ; i < treeNode->m_children->size() ; i++)
		{
			menuAppend(a_childAction,menu,treeNode->m_children->at(i));
			//qDebug()<<treeNode->m_children->at(i)->m_data.name;
		}
		//qDebug() <<a_childAction->text();
//		a_childMenuAction->setMenu(childMenu);
		//qDebug() << "---------------";
	}
}
